﻿using System.Collections.Generic;
using System.Linq;
using MiniWeb.Core.Dtos;
using MiniWeb.Core.Entities;
using MiniWeb.Core.Entities;
using WFramework.MvcPager;
using WFramework.ORM;

namespace MiniWeb.Dao
{
	public  class StmpConfigDao:BaseDao<StmpConfig>
	{
	     	      public PagedList<StmpConfig> GetPagedList(string stmpname,int pageIndex, int pageSize)
        {
            var sql = Sql.Builder.Where("1=1");
           if(!string.IsNullOrEmpty(stmpname))
            {
                sql.Where("StmpName Like @0", string.Format("%{0}%",stmpname));
            }
            sql.OrderBy("CreateDate DESC");
            return PagedList<StmpConfig>(pageIndex, pageSize, sql);
        }
        
	     	     public PagedList<StmpConfig> GetPagedList(int pageIndex, int pageSize)
        {
            var sql = Sql.Builder.Where("1=1");
           sql.OrderBy("CreateDate DESC");
            return PagedList<StmpConfig>(pageIndex, pageSize, sql);
        }
        
         public StmpConfig GetById(int id)
        {
            var sql = Sql.Builder.Where("id = @0", id);
            return FirstOrDefault(sql);
        }
        
          public void Delete(int id)
        {
            var sql = Sql.Builder.Where("ID = @0", id);
            Delete(sql);
        }
        
   		     
		public bool Exists(int id)
		{
			var sql = Sql.Builder.Where("ID = @0", id);
            if(FirstOrDefault(sql)!=null)
            {
                return true;
            }
            return false;
		}
		
	    public List< StmpConfig> GetAll(int? top,string strwhere,string orderby)
        {
            string sqltop = "";
            if(top !=null)
            {
                sqltop = "TOP " + top.ToString() + " * ";
            }
            else
            {
                sqltop = " * ";
            }
            var sql = Sql.Builder.Select(sqltop).From(" StmpConfig WITH(NOLOCK)");
            if(!string.IsNullOrEmpty(strwhere))
            {
                sql.Where(strwhere);
            }
             if(!string.IsNullOrEmpty(orderby))
            {
                sql.OrderBy(orderby);
            }else
            {
              sql.OrderBy("CreateDate Desc");
            }
            
            return Query< StmpConfig>(sql).ToList();
        }
	

   
	}
}